package com.hxh.entity;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hxh.config.ApplicationContextUtil;
import com.hxh.dao.ProjectDatasourceDao;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;


/**
 * 项目配置
 **/
@Data
public class Project implements Serializable{
    private static final long serialVersionUID = 1L;

    /**
     * 
     * 索引:PRI
     **/
    private Integer id;

    /**
     * 项目名称
     **/
    private String name;

    /**
     * 备注
     **/
    private String rmk;

    /**
     * 数据源id
     **/
    private Integer datasourceId;

    /**
     * 多数据源id
     */
    private String mutilDatasourceId;
    private List<ProjectDatasource> mutilDatasourceList;

    public List<ProjectDatasource> getMutilDatasourceList() {
       if (StrUtil.isBlank(mutilDatasourceId)){
           return null;
       }
        ProjectDatasourceDao projectDatasourceDao = ApplicationContextUtil.getOneBeanByType(ProjectDatasourceDao.class);
        String[] ids = mutilDatasourceId.split(",");
        return projectDatasourceDao.selectByIds(Arrays.asList(ids));
    }

    /**
     * 项目模板
     **/
    private String template;
    private TemplateConfig templateConfig;

    /**
     * 选用的组件
     **/
    private String additionComponent;

    /**
     * 创建时间
     **/
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private java.util.Date createTime;

    /**
     * 更新时间
     **/
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private java.util.Date updateTime;

    private ProjectDatasource projectDatasource;
    private ProjectDetail frontendProject;
    private ProjectDetail backendProject;

}
